package com.erlang.controller;

import com.erlang.entity.User;
import com.erlang.exception.MyException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 *
 * @author ZGQ
 */
@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String hello() {
        int a = 1/0;
        return " hello Spring Boot ...4444";
    }

    @GetMapping("/testJackson")
    public User testJson() {
        return new User(0, "1234", "1234", new Date());
    }

    @RequestMapping("/testExc")
    public Object testExc() {

        throw new MyException("400","滴答滴答...");
        // TODO 为什么此处的异常抛出之后,
        /**
         * {
         *   "msg": null,
         *   "code": 100,
         *   "url": "http://localhost:8080/testExc"
         * }
         * 而不是
         * {
         *   "msg": 滴答滴答...,
         *   "code": 400,
         * }
         *
         *  去除掉全局异常之后:
         *  异常为:
         *  com.erlang.exception.MyException: null
         */
    }
}
